package kr.hkit.androidcomplete03.ch281.common;

import java.util.ArrayList;

import kr.hkit.androidcomplete03.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	Context context;
	ArrayList<Item> itemLists ;
	private LayoutInflater inflater;
	
	public MyAdapter(Context context , ArrayList<Item> itemLists){
		this.context = context;
		this.itemLists = itemLists;
		inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
	}
	
	
	@Override
	public int getCount() {
		return itemLists.size();
	}

	@Override
	public Object getItem(int index) {
		// TODO Auto-generated method stub
		return itemLists.get(index).getItemName();
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = inflater.inflate(R.layout.ch281_xmlparser_itemlow, parent, false);
		}
		
		TextView itemName = (TextView) convertView.findViewById(R.id.ch281_xmlparser_itemlowitemName);
		TextView itemMaker = (TextView) convertView.findViewById(R.id.ch281_xmlparser_itemlowmakerName);
		TextView itemPrice = (TextView) convertView.findViewById(R.id.ch281_xmlparser_itemlowitemPrice);
		
		itemName.setText(itemLists.get(position).getItemName());
		itemMaker.setText(itemLists.get(position).getItemMaker());
		itemPrice.setText(String.valueOf(itemLists.get(position).getItemPrice()));
		
		return convertView;
	}

}
